##############################
# Replication code for Harbers and Ingram  
# PSRM paper, revision, and revision #2
# Previous versions presented at APSA 2016;Southwest Mixed-Methods Workshop 2016; 
# SPSA 2017; APSA 2017; APSA 2018
# Matthew C. Ingram
# University at Albany, SUNY
# contact: mingram@albany.edu
# Last updated: 20181206
##############################

# NOTE:
# Run this "setup" script prior to running main or appendix scripts
# See README file

###########################################################
#
# Environment and Session Information
#
###########################################################

# System Information 
# Sys.info()
#sysname          release          version         nodename          machine 
#"Windows"       ">= 8 x64"     "build 9200" "DLD1648-MI314A"         "x86-64"

############################
# install necessary packages
############################

install.packages("pacman")
library(pacman)
pacman::p_load(spdep, graphicsQC, prettyR, RColorBrewer, car, grid, gridExtra, classInt, rgeos, maptools, 
               rgdal, weights, xts, spacetime, plm, ggplot2, maps, plm, plyr, 
               parallel, scales, cowplot, AER, 
               psych, reticulate)

# note: if used install.packages() command rather than pacman, installing is not enough; need to open library with library() command
# note re library(maptools):
# gpclibPermit()   # if get error msg from maptools, use this to enable gpclib for maptools

# note: if using older version of R, R reports errors with some of these packages
# however, I have found that some still work despite error messages here (e.g., read.gal)
# best solution is to update to latest version of R

# check what packages are installed/loaded
#library()     # tells you what packages are installed on your computer
sessionInfo() # tells you what packages have been loaded for current session
##########

# set other options
options(digits=3)

#################################
#
# SET WORKING DIRECTORY
# 
#################################

# note: this is set to my own working directory; select your own
# if don't know working directory, use getwd()
#getwd()

# if using remote cluster (HPC)
#setwd('/network/rit/home/mi122167/apsa2016')

#path <- 'C:/Users/mi122167/Dropbox/Met Matt/PSRM2018/replicationmaterials2018v2'
#setwd(path)

# create subdirectories
dir.create('./code', showWarnings = TRUE)
dir.create('./data', showWarnings = TRUE)
dir.create('./data/original', showWarnings = TRUE)
dir.create('./data/working', showWarnings = TRUE)
dir.create('./figures', showWarnings = TRUE)
dir.create('./figures/appendix', showWarnings = TRUE)
dir.create('./tables', showWarnings = TRUE)
dir.create('./shapefiles', showWarnings = TRUE)

# optional: check folder contents
#list.files()
# dir()

# end